package com.math3d;

import com.system.GLLog;

import java.util.Arrays;

/**
 * @Author: clm
 * @Date: 2018-10-15
 */

public class Vector4fv {
    public float vec[] = new float[4];
    public Vector4fv(){

    }
    public Vector4fv(float[] vec) {
        this.vec = vec;
    }
    public Vector4fv(float x, float y, float z, float w){
        vec[0] = x;
        vec[1] = y;
        vec[2] = z;
        vec[3] = w;
    }
    public static Vector4fv inter(Vector4fv v1, Vector4fv v2, float t){
        float s = 1 - t;
        Vector4fv result = new Vector4fv();
        result.vec[0] = v1.vec[0] * s + v2.vec[0] * t;
        result.vec[1] = v1.vec[1] * s + v2.vec[1] * t;
        result.vec[2] = v1.vec[2] * s + v2.vec[2] * t;
        result.vec[3] = 1.0f;
        return result;
    }
    public float[] getVec() {
        return vec;
    }

    public void setVec(float[] vec) {
        this.vec = vec;
    }
    public void setTo(float x, float y, float z, float w){
        vec[0] = x;
        vec[1] = y;
        vec[2] = z;
        vec[3] = w;
    }

    /**
     * 相加
     * @param tag
     * @return
     */
    public Vector4fv add(Vector4fv tag){
        return new Vector4fv(vec[0] + tag.vec[0], vec[1] + tag.vec[1], vec[2] + tag.vec[2], vec[3] + tag.vec[3]);
    }
    public void fastAdd(float result[], Vector4fv tag){
        result[0] = vec[0] + tag.vec[0];
        result[1] = vec[1] + tag.vec[1];
        result[2] = vec[2] + tag.vec[2];
        result[3] = vec[3] + tag.vec[3];
    }
    public Vector4fv sub(Vector4fv tag){
        Vector4fv result = new Vector4fv(vec[0] - tag.vec[0], vec[1] - tag.vec[1], vec[2] - tag.vec[2], 1.0f);
        return result;
    }

    @Override
    public String toString() {
        return "Vector4fv{" +
                "vec=" + Arrays.toString(vec) +
                '}';
    }
}
